<template>
  <div class="app-container uni-scroll" style="height: calc(100vh - 185px)">
    <el-form label-width="150px" :inline="true">
      <el-form-item :label="$t('gzh')">
        <el-switch
          v-model="pushConfig.openPushGzh"
        />
      </el-form-item>
      <el-form-item :label="$t('gzh')+$t('delay')">
        <el-time-picker
          v-model="pushConfig.canWeChatTime"
          value-format="HH:mm:ss"
          arrow-control
        />
      </el-form-item>

    </el-form>
    <el-form label-width="150px" :inline="true">
      <el-form-item :label="$t('email')">
        <el-switch
          v-model="pushConfig.openPushEmail"
        />
      </el-form-item>
      <el-form-item :label="$t('email')+$t('delay')">
        <el-time-picker
          v-model="pushConfig.canEmailTime"
          value-format="HH:mm:ss"
          arrow-control
        />
      </el-form-item>
      <el-form-item :label="$t('email')">
        <el-input v-model="pushConfig.email" />
      </el-form-item>

    </el-form>
    <el-form label-width="150px" :inline="true">
      <el-form-item :label="$t('sms')">
        <el-switch
          v-model="pushConfig.openPushSms"
          disabled
        />
      </el-form-item>
      <el-form-item :label="$t('sms')+$t('delay')">
        <el-time-picker
          v-model="pushConfig.canSmsTime"
          value-format="HH:mm:ss"
          arrow-control
        />
      </el-form-item>
      <el-form-item :label="$t('phoneNumber')">
        <el-input v-model="pushConfig.smsNumber" />
      </el-form-item>
    </el-form>
    <el-form label-width="150px">
      <el-form-item :label="'webSocket'">
        <el-switch
          v-model="pushConfig.openPushWs"
        />
      </el-form-item>
      <el-form-item :label="$t('linkage')">
        <el-switch
          v-model="pushConfig.openLinkageExecute"
        />
      </el-form-item>
      <el-form-item :label="'webSocket '+$t('warn')+$t('time')">
        <el-input
          v-model="pushConfig.wsWarnDuration"
          type="number"
        >
          <template slot="append">ms</template>
        </el-input>
      </el-form-item>
      <el-form-item :label="'webSocket '+$t('info')+$t('time')">
        <el-input
          v-model="pushConfig.wsInfoDuration"
          type="number"
        >
          <template slot="append">ms</template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="input-group" @click="save">{{ $t("save") }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getPush, insertOrUpdatePush } from '@/api/auth/authUserConfigPushApi'
import {
  successNotice
} from '@/util/common'
import { getUserId } from '@/util/storage'
export default {
  name: 'PushConfig',
  data() {
    return {
      pushConfig: {
        openPushWs: null,
        openLinkageExecute: null,
        openPushEmail: null,
        openPushGzh: null,
        openPushSms: null,
        canWeChatTime: null,
        canEmailTime: null,
        canSmsTime: null,
        email: null,
        smsNumber: null,
        configId: null,
        wsInfoDuration: 0,
        wsWarnDuration: 0
      },
      userId: getUserId()
    }
  },
  mounted() {
    this.getSetting()
  },
  created() {

  },
  methods: {
    getSetting() {
      getPush({
        userId: this.userId
      }).then(res => {
        const { code, data } = res
        if (code === '200') {
          this.pushConfig = data
        }
      })
    },
    save() {
      insertOrUpdatePush({
        userId: getUserId(),
        ...this.pushConfig
      }).then(res => {
        const { code } = res
        if (code === '200') {
          successNotice(this)
        }
      })
    }
  }
}
</script>
